#!/bin/bash

APP_DIR=edge/*
OTA_FILE=ota.tar
APP_FILE=edge.tar
SIG_FILE=signature
key="71776572747975696f706c6b6a686766" # qwertyuioplkjhgf
iv="7a786376626e6d6c6b6a686766647361" # zxcvbnmlkjhgfdsa

rm ${OTA_FILE} 
tar cf ${APP_FILE} ${APP_DIR}

source_str=$(md5sum ${APP_FILE}| cut -d ' ' -f1) 
encrypt_str=$(echo "${source_str}" | openssl enc -e -aes-128-cbc -base64 -K ${key} -iv ${iv} -nosalt)
echo ${encrypt_str}>${SIG_FILE}

echo ${source_str} ${encrypt_str}

tar cf ${OTA_FILE} ${APP_FILE} ${SIG_FILE}

rm ${APP_FILE} ${SIG_FILE}

